<?php
namespace Duobao\Model;

use Org\Util\JWT;
use Think\Model;


class CartModel extends Model{

    protected $tableName ='member_go_record';

    /**
     * 判断一个商品能否加入购物车
     */
    public function judgmentJoinCart($id){
        $model = new \Think\Model();

        $condition['id'] = $id;
        $result = $model->table('__SHOPLIST__')->where($condition)->getField('shenyurenshu');

        if($result > 0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 获取多商品id，返回对应id的商品的name，img，总需人次，和剩余人次,
     * 查询条件是剩余人数大于0
     */
    public function listCart($idarr){
        $model = new \Think\Model();

        $condition['id'] = array('in',$idarr);
        $condition['shenyurenshu'] = array('gt',0);


        $result = $model->table('__SHOPLIST__')->field('id,title,thumb,zongrenshu,shenyurenshu')->where($condition)->select();

        if($result){

            $tmp = array();
            foreach($result as $item){
                $tmp['id'] = $item['id'];#商品id
                $tmp['goodsName'] = $item['title'];#商品名称
                $tmp['img'] = C('CDN_DOMAIN') . C('UPLOAD_PATH') .$item['thumb'];#压缩图
                $tmp['totalNeed'] = $item['zongrenshu'];#总需人数
                $tmp['surplus'] = $item['shenyurenshu'];#剩余人数

                $list[] = $tmp;
            }
        }

        return $list;

    }
    /* Cart model end */
}